package com.ssh.service;

import java.util.List;

import com.ssh.dao.IGoodsDAO;
import com.ssh.model.Goods;

public class GoodsService implements IGoodsService {

	private IGoodsDAO GoodsDAO = null;

	@Override
	public void addGoods(Goods g) {
		GoodsDAO.save(g);
	}

	@Override
	public void delGoods(Goods g) {
		GoodsDAO.delete(g);
	}

	@Override
	public List<Goods> findAll() {
		return GoodsDAO.findAll();
	}

	@Override
	public Goods findByName(String name) {
		List<Goods> list = GoodsDAO.findByName(name);
		if (list == null) {
			return null;
		}
		return list.get(0);

	}

	@Override
	public void updateGoods(Goods g) {
		GoodsDAO.attachDirty(g);

	}

	public void setGoodsDAO(IGoodsDAO GoodsDAO) {
		this.GoodsDAO = GoodsDAO;
	}

	public IGoodsDAO getGoodsDAO() {
		return GoodsDAO;
	}
}